﻿#include <QWidget>
#include <QVBoxLayout>
#include <QTimer>
#include <QPropertyAnimation>
#include <QPushButton>
#include <QPainter>
#include <QStyle>
#include <QEnterEvent>

// 悬停按钮组类
class HoverButton : public QWidget {
    Q_OBJECT
    Q_PROPERTY(int expandWidth READ expandWidth WRITE setExpandWidth)
public:
    explicit HoverButton(QWidget *parent = nullptr);
    int expandWidth() const;
    void setExpandWidth(int width);
    void addButton(const QString &text, const QIcon &icon = QIcon());
protected:
    void enterEvent(QEnterEvent *event) override;
    void leaveEvent(QEvent *event) override;
    void paintEvent(QPaintEvent *event) override;
private slots:
    void expand();
    void collapse();
private:
    int m_collapsedWidth;
    int m_expandedWidth;
    bool m_isExpanded;
    QVBoxLayout *m_layout;
    QList<QPushButton*> m_buttons;
    QPropertyAnimation *m_animation;
    QTimer *m_collapseTimer;
};
